package com.yunxi.service.dubboService.impl.sat;

import com.yunxi.model.sat.SatTestDrive;
import com.yunxi.qrtz.service.TestDriveRemindJobDubboService;
import com.yunxi.sat.pojo.SatMessAddVO;
import com.yunxi.sat.pojo.SatTestDriveVO;
import com.yunxi.service.localService.sat.SatConfigService;
import com.yunxi.service.localService.sat.SatMessService;
import com.yunxi.service.localService.sat.SatTestDriveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import java.util.List;

/**
 * <p>
 * 试驾超期提醒 服务实现类
 * </p>
 *
 * @author caoYong
 * @since 2019-08-01
 */

public class TestDriveRemindJobDubboServiceImpl implements TestDriveRemindJobDubboService {

    @Autowired
    @Qualifier(value = "satTestDriveServiceImpl")
    SatTestDriveService satTestDriveService;

    @Autowired
    @Qualifier(value = "satConfigServiceImpl")
    SatConfigService satConfigService;

    @Autowired
    @Qualifier(value = "satMessServiceImpl")
    SatMessService satMessService;


    /**
     * 新增试驾后15分钟,生成消息提醒试驾或取消试驾
     * @throws Exception
     */
    @Override
    public void remindTestDrive() throws Exception {
        //1.查询超期未经提醒的试驾计划
        List<SatTestDriveVO> list = satTestDriveService.getLateTestDrive();
        if(list != null && list.size() > 0){
            for (SatTestDriveVO vo :list){
                //更新是否提醒为是
                SatTestDrive satTestDrive = satTestDriveService.getById(vo.getDriveId());
                satTestDrive.setIsRemind(1);
                satTestDriveService.saveOrUpdate(satTestDrive);

                SatMessAddVO satMessAddVO = new SatMessAddVO();
                satMessAddVO.setType("21");
                satMessAddVO.setTemplateType(18);
                satMessAddVO.setCustomerName(vo.getCustomerName());
                satMessAddVO.setCustomerNo(vo.getCustomerNo());
                satMessAddVO.setSalesConsultantNo(vo.getSalesConsultantNo());
                satMessAddVO.setReceiveRoleCode("rolePartnerTestDrive");
                satMessAddVO.setBusinessKey(satTestDrive.getDriveId());
                satMessService.newMess(satMessAddVO);

            }
        }
    }
}
